package com.ccb.jyzx.expand.ouapi.controller;

import com.ccb.jyzx.expand.ouapi.beans.DutyInfo;
import com.ccb.jyzx.expand.ouapi.service.DutyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ccb.jyzx.expand.ouapi.view.request.DepIdRequest;
import com.ccb.jyzx.expand.ouapi.view.request.IdRequest;
import com.ccb.jyzx.expand.ouapi.view.request.UserIdRequest;

import java.util.ArrayList;
import java.util.List;

/**
 * @author XIEFEI
 * @date 2019-11-13 14:10
 * @Description 岗位信息查询接口
 **/
@RequestMapping("/ooapi/api/duty")
@Api(tags = "岗位信息相关接口")
@Controller
public class DutyInfoController {

    @Autowired
    DutyService dutyService;

    @ApiOperation(value = "根据id查询岗位信息", notes = "根据id查询岗位信息")
    @ResponseBody
    @PostMapping(value = "getById", consumes = "application/json;charset=UTF-8")
    public DutyInfo getReport(@RequestBody IdRequest json) {
        return StringUtils.isNotBlank(json.getId()) ? dutyService.getById(json.getId()) : new DutyInfo();
    }

    @ApiOperation(value = "查询所有岗位信息", notes = "查询所有岗位信息")
    @ResponseBody
    @PostMapping(value = "getAll", consumes = "application/json;charset=UTF-8")
    public List<DutyInfo> getAll() {
        return dutyService.getAll();
    }

    @ApiOperation(value = "根据部门id查询岗位信息", notes = "根据部门id查询岗位信息")
    @ResponseBody
    @PostMapping(value = "getByDepId", consumes = "application/json;charset=UTF-8")
    public List<DutyInfo> getByDepId(@RequestBody DepIdRequest json) {

        return StringUtils.isNotBlank(json.getDepId())?dutyService.getByDepId(json.getDepId()):new ArrayList<>();
    }

    @ApiOperation(value = "根据用户Id查询该员工岗位信息", notes = "根据用户Id查询该员工岗位信息")
    @ResponseBody
    @PostMapping(value = "getByUserId",consumes = "application/json;charset=UTF-8")
    public List<DutyInfo> getByUserId(@RequestBody UserIdRequest json){
        return StringUtils.isNotBlank(json.getUserId())? dutyService.getByUserId(json.getUserId()):new ArrayList<>();
    }

}
